package com.web.itemService.utils;


import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import com.web.itemService.properties.jwtProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;
@Component
public class jwtUtils {
    @Autowired
    jwtProperty jwtProperty;


    public  String getJwt(Map<String, Object> claims) {
        String jwt = Jwts.builder().
                signWith(SignatureAlgorithm.HS256, jwtProperty.getSecret())
                .addClaims(claims).setExpiration(new Date(System.currentTimeMillis() + jwtProperty.getJwtExpiration()))
                .compact();
        return jwt;
    }

    public  Map<String, Object> parseJwt(String jwt) {
        return Jwts.parser().setSigningKey(jwtProperty.getSecret()).parseClaimsJws(jwt).getBody();
    }
}